package com.qfedu.fmmall.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.qfedu.fmmall.service.ProductCommentsService;
import com.qfedu.fmmall.service.ProductService;
import com.qfedu.fmmall.service.ShoppingCartService;
import com.qfedu.fmmall.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
@Api(value = "提供商品信息相关的接口",tags = "商品管理")
public class ProductController {
    @Autowired
    private ProductService productService;
    @Autowired
   private ProductCommentsService productCommentsService;
    @Autowired
    private ShoppingCartService shoppingCartService;
    @GetMapping("/detail-info/{pid}")
    @ApiOperation(value = "商品信息接口")
    public ResultVO getProduct(@PathVariable("pid")String id){
     return productService.getProduct(id);
  }
    @GetMapping("/detail-params/{pid}")
    @ApiOperation(value = "查询商品参数信息")
    public ResultVO productParams(@PathVariable("pid")String id){
        return productService.productParams(id);
    }
    @ApiOperation("商品评论信息查询接⼝")
    @GetMapping("/detail-commonts/{pid}")
    @ApiImplicitParams({@ApiImplicitParam(name = "pageNum",value="分页的起始下标",required = true,dataType = "int"), @ApiImplicitParam(
            name = "limit",value = "每页显示的记录条数",required = true, dataType = "int"
    )})
    public ResultVO getProductCommonts(@PathVariable("pid") String pid,int pageNum,int limit){
        return productCommentsService.listCommontsByProductId(pid,pageNum,limit);
    }
    @GetMapping("/detail-commontscount/{pid}")
    @ApiOperation(value = "查询商品评价统计接口")
    public ResultVO commontsCountMap(@PathVariable("pid")String id){
        return productCommentsService.commontsCountMap(id);
    }
}

